import { Controller, Post, UseInterceptors, UploadedFile } from '@nestjs/common';
import { UploadService } from './upload.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { CommonResult } from '../utils/result';
import config from '../config/index';

@Controller('/upload')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}
  @Post('/file')
  @UseInterceptors(FileInterceptor('file'))
  async upload(@UploadedFile() file) {
    if (!file) {
      return CommonResult(null, false, 400, '文件为空');
    }

    const resultData = {
      imageUrl: `${config.baseUrl}/images/${file.filename}`,
    };
    return CommonResult(resultData, true, 200);
  }
}
